#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
为缺少中文翻译的英文参数提供中文翻译
"""

import json

def load_json_file(file_path):
    """加载JSON文件"""
    with open(file_path, 'r', encoding='utf-8') as f:
        return json.load(f)

def save_json_file(data, file_path):
    """保存JSON文件"""
    with open(file_path, 'w', encoding='utf-8') as f:
        json.dump(data, f, ensure_ascii=False, indent=2)

def main():
    """主函数"""
    # 需要翻译的参数映射
    translations = {
        "1st seat row  legroom (maximum with seat in rearmost midheight position)": "第一排座椅腿部空间(座椅最后方中等高度位置最大值)",
        "1st seat row  shoulder room": "第一排座椅肩部空间",
        "1st seat row headroom (without sunroof)": "第一排座椅头部空间(无天窗)",
        "2nd seat row  legroom": "第二排座椅腿部空间",
        "2nd seat row headroom (without sunroof)": "第二排座椅头部空间(无天窗)",
        "Approach angle  (unloaded vehicle)": "接近角(空载)",
        "Departure angle (unloaded vehicle)": "离去角(空载)",
        "Front Track (max. or min. depending on wheel offset)": "前轮距(根据轮毂偏距取最大/最小值)",
        "Front overhang (with License Bracket)": "前悬(含牌照支架)",
        "Fuel Tank Capacity": "燃油箱容量",
        "Gross Train Mass": "总拖拽质量",
        "Gross Vehicle Mass": "车辆总质量",
        "Ground Clearance   (fully loaded)": "离地间隙(满载)",
        "Ground Clearance (unloaded)": "离地间隙(空载)",
        "Kerbweight": "整备质量",
        "Load opening width (mm)": "装载开口宽度(毫米)",
        "Loading length at floor to second row": "地板至第二排装载长度",
        "Loading width between wheel houses": "轮罩间装载宽度",
        "Max loading height": "最大装载高度",
        "Max. Towable Mass (braked) (12% gradient)": "最大拖拽质量(制动)(12%坡度)",
        "Max. Towable Mass (unbraked)": "最大拖拽质量(非制动)",
        "Overall height unladen": "整车高度(空载)",
        "Overall length without towbar": "整车长度(不含拖车杆)",
        "Overall width with folded-back mirrors": "整车宽度(后视镜折叠)",
        "Overall width with mirrors": "整车宽度(含后视镜)",
        "Rear Track (max. or min. depending on wheel offset)": "后轮距(根据轮毂偏距取最大/最小值)",
        "Rear overhang (with License Bracket)": "后悬(含牌照支架)",
        "Roof Load Limit": "车顶载荷限制",
        "Seating Capacity": "座椅容量",
        "Turning circle – kerb to kerb": "转弯半径-路缘到路缘",
        "Vertical Load Limit": "垂直载荷限制",
        "miro": "车辆自重"
    }
    
    # 加载现有的参数映射
    param_mappings = load_json_file('paramset_en_cn.json')
    
    # 更新翻译
    updated_count = 0
    for en_param, cn_translation in translations.items():
        if en_param in param_mappings:
            if param_mappings[en_param] == en_param:  # 之前是临时使用英文作为中文
                param_mappings[en_param] = cn_translation
                updated_count += 1
                print(f"更新翻译: {en_param} -> {cn_translation}")
    
    # 按字母顺序排序
    sorted_mappings = dict(sorted(param_mappings.items()))
    
    # 保存更新后的文件
    save_json_file(sorted_mappings, 'paramset_en_cn.json')
    
    print(f"\n成功更新了 {updated_count} 个参数的中文翻译")
    print(f"paramset_en_cn.json 文件已更新，总共包含 {len(sorted_mappings)} 个参数映射")

if __name__ == "__main__":
    main()
